#!/bin/bash

# Slackware build script for bdfedit

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/
# for details.

# Why do we need another BDF editor? Because gbdfed keeps segfaulting on
# me. Also, bdfedit's UI uses a single window instead of the multiple
# windows gbdfed uses (which is better will be a matter of personal
# preference, but I prefer 1 window). fontforge is also capable of
# editing BDFs but its UI is irritating (to me anyway).

# Yes, this is old software that hasn't been maintained in 12+ years,
# but it works fine.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=bdfedit
VERSION=${VERSION:-1.3}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

ARCH=noarch
# no CFLAGS or LIBDIRSUFFIX needed here

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM$VERSION
tar xvf $CWD/$PRGNAM$VERSION.tar.gz
cd $PRGNAM$VERSION
chown -R root:root .

# upstream perms are bad, do this instead of find|chmod.
chmod 755 .
chmod 644 *

mkdir -p $PKG/usr/bin

# instead of having bdfedit source completion.tcl, just include its
# contents directly in bdfedit. Avoids having to create a private
# lib or share dir. Also set correct path to wish in #! line.
( echo '#!/usr/bin/wish -f'
  cat completion.tcl
  sed '1,5d' $PRGNAM ) \
		> $PKG/usr/bin/$PRGNAM

chmod 755 $PKG/usr/bin/$PRGNAM

# .desktop and icon made for this build. Don't laugh, I'm not
# a graphic designer, OK?
mkdir -p $PKG/usr/share/applications $PKG/usr/share/pixmaps
cat $CWD/$PRGNAM.png > $PKG/usr/share/pixmaps/$PRGNAM.png
cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop

# man page written for this build (copy/paste from readme, mostly).
mkdir -p $PKG/usr/man/man1
gzip -9c < $CWD/$PRGNAM.1 > $PKG/usr/man/man1/$PRGNAM.1.gz

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a $PRGNAM.* *.$PRGNAM $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
